<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../lib/vue-2.6.12.js"></script>
</head>
<body>
    <div id="box">
        <div v-dir>hello directive</div>
        <!-- 指令的值如果不加引号，vue会以变量来处理 -->
        <div v-dir=" 'blue' ">hello directive</div>
        <div v-dir=" 'yellow' ">hello directive</div>
        <!-- color为变量 -->
        <div v-dir=" color ">hello directive</div>

    </div>
    <script>
        //创建了一个指令dir
        // Vue.directive("dir",{
        //     inserted(el,binding){
        //         el.style.background = binding.value ? binding.value : "red"
        //     }    
        // })  
        Vue.directive("dir",{
             inserted(el,binding){
              el.style.background = binding.value ? binding.value : "red"   
             }

        })
        new Vue({
            el:"#box",
            data:{
                color : "#ccc"
            }
        })
    </script>
</body>
</html>